<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        body {
            background-color: #663399;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
        }
        .login-container {
            background-color: #fff;
            padding: 30px 50px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
            width: 350px;
            text-align: center;
        }
        .login-title {
            color: #663399;
            margin-bottom: 25px;
            font-size: 24px;
            font-weight: bold;
        }
        .login-input {
 width           : 100%;
            padding: 15px;
            margin-bottom: 20px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        .login-input:focus {
            outline: none;
            border-color: #663399;
            box-shadow: 0 0 5px rgba(102, 51, 153, 0.3);
        }
        .login-button {
            width: 100%;
            padding: 15px;
            background-color: #663399;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.2s;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .login-button:hover {
            background-color: #4d2675;
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
        }
        .login-button:active {
            transform: translateY(0);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-size: 15px;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2 class="login-title">用户登录</h2>
        <div class="form-group">
            <label for="username">用户名：</label>
            <input type="text" id="username" class="login-input" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码：</label>
            <input type="password" id="password" class="login-input" placeholder="请输入密码">
        </div>
        <button class="login-button" onclick="validateForm()">登录</button>
    </div>

    <script>
        function validateForm() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            if (!username || !password) {
                alert('用户名和密码不能为空');
                if (!username) document.getElementById('username').focus();
                if (!password) document.getElementById('password').focus();
                return;
            }

            if (username.length < 8 || username.length > 20) {
                alert('用户名长度必须在8到20个字符之间               ');
 document.getElementById('username').focus();
                return;
            }

            if (password.length < 8 || password.length > 20) {
                alert('密码长度必须在8到20个字符之间');
                document.getElementById('password').focus();
                return;
            }

            alert('登录成功！');
        }
    </script>
</body>
</html>